<template>

  <el-dialog :title="'商品审核意见'" :close-on-click-modal="false" :visible.sync="visible" width="50%">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
      <el-form-item label="不通过原因" prop="auditSuggest" label-width="150px">
        <el-input type="textarea" v-model="dataForm.auditSuggest" placeholder="审核意见"></el-input>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" :disabled="submitVisible" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        dataForm: {
          auditSuggest: ''
        },
        dataRule: {
          auditSuggest: [
            { required: true, message: '审核意见', trigger: 'blur' }
          ]
        },
        visible: false,
        submitVisible: false,
        shopGoodsId: '',
        shopId: ''
      }
    },
    methods: {
      init (shopGoodsId, shopId) {
        this.visible = true
        this.submitVisible = false
        console.log('商品id:%s-商铺id:%s', shopGoodsId, shopId)
        this.shopGoodsId = shopGoodsId
        this.shopId = shopId
        this.dataForm.auditSuggest = ''
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
        })
      },
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.submitVisible = true
            this.$http({
              url: this.$http.adornUrl(`/pig-center-biz/shopgoods/back/auditReject`),
              method: 'post',
              data: this.$http.adornData({
                'shopGoodId': this.shopGoodsId,
                'cid': this.shopId,
                'auditSuggest': this.dataForm.auditSuggest
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshView')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>

<style>
</style>
